package basic;

import java.util.HashMap;

public class InternalClass {
    public static void main(String[] args) {
        Outer ot = new Outer("wangjh");
        Outer.Inner oi = ot.new Inner();
        oi.hello();
        ot.asyncHello();

        HashMap<String, String> map1 = new HashMap<>();
        HashMap<String, String> map2 = new HashMap<String, String>() {}; // 匿名类!
        HashMap<String, Integer> map3 = new HashMap<String, Integer>() {
            {
                put("A", 1);
                put("B", 2);
            }
        };
        System.out.println(map3.get("A"));

        Outer.StaticNested os = new Outer.StaticNested();
        Outer.NAME = "rename";
        os.hello();

    }
}

class Outer {
    private String name;
    public static String NAME="static-name";

    public Outer(String name) {
        this.name = name;
    }

    class Inner {
        void hello(){
            System.out.println("Hello, "+ name + " I'm from innner!");
        }
    }

    void asyncHello(){
        Runnable r = new Runnable() {
            @Override
            public void run() {
                System.out.println("Hello, "+ Outer.this.name);
            }
        };
        new Thread(r).start();
    }

    static class StaticNested {
        void hello() {
            System.out.println("Hello, " + Outer.NAME);
        }
    }
}